import { Component, Input, OnInit, Host, Inject, forwardRef } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { TopicInfo, RowInfo } from '../../models/quesinfo';

/**
 * Generated class for the QuestionSortPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */


@Component({
  selector: 'page-question-sort',
  templateUrl: 'question-sort.html',
})
export class QuestionSortPage {
  @Input() topic: TopicInfo;@Input() poneSet: Array<any>;
  @Input() topicIndex;
  topicIndexshow;

  constructor(public navCtrl: NavController, public navParams: NavParams) {
  }
  ngOnInit(): void {
    this.topicIndexshow=this.topicIndex+1;
    //
    this.zlqsort();
  }
  zlqsort(){
    let templistR=new Array<RowInfo>();
    templistR=this.topic.listRow;
    this.topic.listRow=[];
    for (var i = 0; i < templistR.length; i++) {
      templistR.forEach((oner,indexr) => {
        if(i==oner.SortQ)
        {
          this.topic.listRow.push(oner);
        }
      });
    }
    //console.log(this.topic.listRow);
  }
  ionViewDidLoad() {
    // //console.log('ionViewDidLoad QuestionSortPage');
  }

  sort(thisr){
     let thisoldsort=thisr.SortQ;
     thisr.SortQ-=1;
     //
     this.topic.listRow.forEach((oner,indexr) => {
      if((thisoldsort-1)==indexr)
      {
        oner.SortQ+=1;
      }
    });
    this.zlqsort();
      // //console.log(this.list);
  }
}
